clc, clear, global e g
e=[9,15]; g=[300;500];

[xx,fval,flag]=fmincon(@fun1,rand(8,1),[],[],[],[],zeros(8,1),[],@fun2)
y=xx(5:7); x=reshape(xx(1:4),[2,2]); 
y1=sum(x,2)             %计算产量
X=[x(:,1)*y',x(:,2)]    %计算原材料甲乙丁丙的分量
y2=sum(X)               %计算原材料甲乙丁丙的使用量

function f=fun1(x);
global e
y=x(5:7); x=reshape(x(1:4),[2,2]); 
f=-e*sum(x,2)+sum(x(:,1))*(6*y(1)+8*y(2)+5*y(3))+7*sum(x(:,2));
end

function [f1,f2]=fun2(x);
global g
y=x(5:7); x=reshape(x(1:4),[2,2]);
f1=[0.1*sum(x(1,:))-x(1,1)*y; 0.1*sum(x(2,:))-x(2,1)*y
    0.1*sum(x,2)-x(:,2); sum(x(:,2))-250
    sum(x(:,1))*y(3)-100
    x(1,1)*(3*y(1)+y(2)+y(3))+2*x(1,2)-2.5*sum(x(1,:))
    x(2,1)*(3*y(1)+y(2)+y(3))+2*x(2,2)-1.5*sum(x(2,:))
sum(x,2)-g];
f2=sum(y)-1;
end